<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 角色设置 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-groups"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-groups">
				
			</div>
		</div>
		
		<!-- TODO 校区信息 -->
		<div class="widget radius-bordered " id="viewer-panel-assets">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 配置资源 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<div id="tree" data-entity="com.app.miwawa.api.system.entity.Assets"></div>
				
				<div class="widget-footer editor-footer-sm">
					<button type="button" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="取消" onclick="handlerCancel(this);" data-refresh-table="#table-groups">
						<i class="glyphicon glyphicon-remove"></i>
					</button>
					<button type="button" class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="保存" onclick="handlerTree(this);">
						<i class="glyphicon glyphicon-ok"></i>
					</button>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-groups" action="/miwawa/default/common/update" method="post" 
			name="com.app.miwawa.api.system.entity.Groups">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
</form>
    
<script type="text/javascript">
<!--
	require(['domReady'],function(domReady){
		domReady(function () {
			loadData();
		});
	});
	
	var groups;
	function loadData(){
		groups = jQuery("#table-groups").data("selectedRow");

		loadAssets();
		
		jQuery(".editor-body-groups").loadform("load", {
			templateId: "#view-groups-template",
			templatePath: "/miwawa/content/system/groups/template.html",
			templateData: groups,
			onLoadSuccess: function(){
				require(['jquery.plugin.form'],function(form){
					form.tooltip("[data-toggle='tooltip']");
				});
			}
		});
	}

	function loadAssets() {
		require(['moment','jquery.plugin.form','jquery.bootstrap.tree'],function(moment, form, tree){
			jQuery('#createDate').val(moment().format("YYYY-MM-DD"));
			
			form.tooltip("[data-toggle='tooltip']");
			
			tree.init("#tree", {
				url: "/miwawa/system/assets/"+groups.id+"/tree.json",
				querys: {
					"limit": "0",
					"offset": "0",
					"and": [{"operator":"EQ", "fieldName":"systemid", "fieldValue":"297ebe0e53d648370153d64dbefc0002"}],
					"order": [{"sort":"code", "order":"asc"}]
				}
			});
		});
	}
	
	function handlerTree(trigger){
		var params = [], nodes = jQuery('#tree').treeview('getChecked');
		
		for(var i in nodes){
			var node = nodes[i];
			params.push({
				"groupsid": groups.id,
				"assetsid": node.id,
				"assetspid": node.pid,
				"assetsCode": node.code,
				"assetsType": node.type,
				"status": "0",
				"invalid": "F"
			});
		}
		
		jQuery.ajaxsend({
			url: "/miwawa/system/assets/"+groups.id+"/update",
			data: {
				"entityClass": "com.app.miwawa.api.system.entity.Auths",
				"beans": params
			},
			success: function(data){
				if(data){
					jQuery(trigger).parent().hide();
				}
			}
		});
	}
//-->
</script>